/**
 * Demo file for Moodgets library test: A widgets library built on mootools
 * @author Maurizio Conventi conventi@inwind.it http://www.moodgets.com
 * @license MIT Style License 
 */
jQuery.noConflict();
function getWebSource(start,limit,webSEC){
	start = start == undefined ? 0 : start;
	var data = {"start": start,"limit":limit};
	jQuery.ajax({
		url:"columnNum",
		data:data,
		type:"post",
		dataType:"json",
		success:function(data){
			bindGridList(data,webSEC);
			//pager(data.total,data.limit,start);
			if(!limit)
				page(data.total,data.limit,1,"pager","getSource",true);
		},
		error:function(data){
			
			jQuery.growlUI('数据加载出错'); 
		}
	   
	});
}
function bindGridList(data,webSEC){
	/*
	var event = "点击详情";
	var dataStore = "[";
	jQuery.each(data.source,function(i,website){
		dataStore +='{"id":"'+website.id+'",webName:"'+website.ftitle+'",creatTime:"'+website.fcreatetime+'",total:"'+data.column[i].CNum+'",event:"'+event+'"},';
	});
	dataStore = dataStore.substring(0,dataStore.length-1);
	dataStore +="]";
	dataStore = eval(dataStore);
	var g_grid = new Grid($('grid'), {
		dataStore: new DataStore(dataStore),
		columnModel: new ColumnModel(columnModel), 
		gridPlugins: [
			//new EditableGridPlugin({requestOptions:{url: 'your url here'}}),
			new SortableGridPlugin(),
			new ResizableGridPlugin(),
			new SelectableGridPlugin({multipleSelection: false}),
			new ColumnOrderingGridPlugin(),
			new SummaryGridPlugin(),
			new FormattedGridPlugin()
		]
	});
	*/
	if(webSEC==-1)
	{
		var html = '<option value="-1" selected="selected">--请选择站点--</option>';
	}
	else var html = '<option value="-1" selected="selected">--请选择站点--</option>';
	if(data.source)
		jQuery.each(data.source,function(i,website){
			if(webSEC==website.id)
			{
				
				html +='<option value='+website.id+' selected="selected">'+website.ftitle+'</option>';
			}
			else html +='<option value='+website.id+'>'+website.ftitle+'</option>';
				
		});
	jQuery("#fsiteid").html(html);
}

			
var columnModel = [{
   header: "ID",
   dataIndex: 'id',
   dataType:'number',
   hidden: true,
   width:50
},{
   header: "网站名称",
   dataIndex: 'webName',
   dataType:'string',
   width:150,
   validator: 'required validate-alpha maxLength:30',
   isEditable: true
},{
   header: "创建时间",
	editableFieldType: 'date',
   dataIndex: 'creatTime',
   dataType:'string',
   validator: 'validate-date dateFormat:%d/%m/%Y',
   width:290,
	  isEditable: true
},{
   header: "栏目总数",
   dataIndex: 'total',
   editableFieldType: 'string',
   validator: 'required validate-numeric',
   dataType:'number',
   //additionalClass: 'rightTextAlign',
   defaultValue: '0',
   summarized: false,
   width:100,
   format: function(p_value){
     return (p_value);
   },
   isEditable: true
},{
	   header: "",
	   dataIndex: 'event',
	   dataType:'string',
	   width:105,
	   validator: 'required validate-alpha maxLength:30',
	   isEditable: false,
	   //onclick:alert('fff')
	}];

window.addEvent('domready', function() {
	var webSEC = document.getElementById("choose_web").value;
	if(webSEC=="")
	{
		getWebSource(0,1000,-1);
	}
	else{getWebSource(0,1000,webSEC);getSource(0,1000,webSEC);}
    //getSource();
});


